import advView from "$v/adv"
import {isLoginRequest} from  "$a/loginApi"
import {logoutRequest} from  "$a/advApi"


export default async (req, res, next) => {
  try {
    await isLoginRequest();
  }catch (e) {
    alert("有异常",e.message)
    if (!e.isLogin){
      return router.go("/login")
    }
  }
  next(advView({
    url: req.url,
    subRoute: res.subRoute()
  }))
  const oLogout = document.querySelector('#oLogout')
  oLogout.onclick = async function () {
    try {
      await logoutRequest()
      localStorage.removeItem("user_token")
      router.go('/login')
    }catch (e) {
      alert("登出异常"+e.message)
    }
  }

}